﻿<localDialog:DialogBase x:Class="MoneyBook.DialogViews.CreateNewAccountItemDialog"
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
           xmlns:localDialog="clr-namespace:MoneyBook.DialogViews"
           xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" 
           xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
           xmlns:li="clr-namespace:MoneyBook.Interactivity"
           xmlns:ld="clr-namespace:MoneyBook.Windows.Data"
           xmlns:lm="clr-namespace:MoneyBook.Windows.Markup"
           xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" 
           Width="300"
           xmlns:sys="clr-namespace:System;assembly=mscorlib"
           x:Name="Self">
    <localDialog:DialogBase.Resources>
        <sys:Boolean x:Key="DialogResultValue">true</sys:Boolean>
    </localDialog:DialogBase.Resources>
    <localDialog:DialogBase.DataContext>
        <localDialog:CreateNewAccountItemDialogModel />
    </localDialog:DialogBase.DataContext>
    <i:Interaction.Triggers>
        <i:EventTrigger SourceObject="{Binding ElementName=Self}"
            EventName="Opened">
            <li:SetPropertyAction TargetObject="{Binding DataContext, ElementName=Self}" PropertyName="TargetAccount">
                <li:Parameter Value="{Binding OpenArg,ElementName=Self}" />
            </li:SetPropertyAction>
            <li:FocusAction TargetObject="{Binding ElementName=ExpenseTextBox}" />
        </i:EventTrigger>
        <i:EventTrigger SourceObject="{Binding DataContext, ElementName=Self}"
            EventName="CreateItemCompleted">
            <li:SetPropertyAction TargetObject="{Binding ElementName=Self}" PropertyName="ResultObject">
                <li:InvokeParameter PropertyName="ResultData" />
            </li:SetPropertyAction>
            <li:SetPropertyAction TargetObject="{Binding ElementName=Self}" PropertyName="DialogResult">
                <li:Parameter Value="True" />
            </li:SetPropertyAction>
        </i:EventTrigger>
    </i:Interaction.Triggers>


    <Grid x:Name="LayoutRoot" Margin="2">
        <i:Interaction.Behaviors>
            <li:DefaultButtonBehavior TargetButton="{Binding ElementName=CreateItemButton}" />
        </i:Interaction.Behaviors>

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <sdk:ValidationSummary Grid.Row="0" Width="400" HorizontalAlignment="Left" />

        <Grid Grid.Row="1" VerticalAlignment="Top">
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition />
                <RowDefinition />
                <RowDefinition />
            </Grid.RowDefinitions>

            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>

            <sdk:Label Target="{Binding ElementName=PurchaseDatePicker}" />
            <sdk:DatePicker Grid.Column="1" SelectedDate="{Binding PurchaseDate, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True}"
                x:Name="PurchaseDatePicker"/>
            
            <sdk:Label Grid.Row="1" Target="{Binding ElementName=CategoryNamesComboBox}" />
            <ComboBox Grid.Row="1" Grid.Column="1" Width="200" ItemsSource="{Binding TargetAccount.Categories}" 
                DisplayMemberPath="CategoryName" x:Name="CategoryNamesComboBox"
                SelectedValue="{Binding SelectedCategory, Mode=TwoWay}" />

            <sdk:Label Grid.Row="2" Target="{Binding ElementName=ExpenseTextBox}" />
            <TextBox Grid.Row="2" Grid.Column="1" Width="200" x:Name="ExpenseTextBox"
                Text="{Binding Expense, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True, Converter={StaticResource NullableConverter}}" />


            <sdk:Label Grid.Row="3" Target="{Binding ElementName=AbstractTextBox}"
                VerticalAlignment="Top" />
            <TextBox Grid.Row="3" Grid.Column="1" x:Name="AbstractTextBox" 
                        Width="200" Height="60" AcceptsReturn="True" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"
                        Text="{Binding Abstract, Mode=TwoWay, ValidatesOnExceptions=True,NotifyOnValidationError=True}" />
        </Grid>

        <StackPanel Orientation="Horizontal" Grid.Row="2" HorizontalAlignment="Right">
            <Button Content="{Binding CreateItemButton,Source={StaticResource Strings}}" 
                x:Name="CreateItemButton">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <li:InvokeMethodAction TargetObject="{Binding DataContext, ElementName=Self}" MethodName="CreateItem"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </Button>
            <Button Content="{Binding CancelButton,Source={StaticResource Strings}}"
                    IsEnabled="{Binding IsProcessing,Converter={StaticResource BooleanInverter}}">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <li:InvokeMethodAction TargetObject="{Binding ElementName=Self}"
                            MethodName="Close" />
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </Button>
        </StackPanel>

    </Grid>
</localDialog:DialogBase>
